#include "businessprocesser.h"
BusinessProcesser::BusinessProcesser(std::shared_ptr<ConnPool> &pro_ptr):pro_ptr(pro_ptr), usrhandler(new UserHandler(pro_ptr)){
    LOG_DEBUG("BusinessProcesser::BusinessProcesser ---> construct success.");
    conn = pro_ptr->getConn();
    // if(*conn){
    //     if(conn->init()){
    //         LOG_INFO("BusinessProcesser::BusinessProcesser ---> create tables success.");
    //     }
    // }
}
BusinessProcesser::~BusinessProcesser(){

}
bool BusinessProcesser::init(){
    if(!createUsertable() || !createBiketable()){
        LOG_ERROR("BusinessProcesser::init ---> create tables failed.");
        return false;
    }
    LOG_DEBUG("BusinessProcesser::init ---> create tables success.");
    return true;
}

bool BusinessProcesser::createUsertable(){
    const char *sql = "\
                    CREATE TABLE IF NOT EXISTS userinfo(\
                    id           int(16)            NOT NULL primary key auto_increment, \
                    mobile       varchar(16)        NOT NULL default '13000000000', \
                    username     varchar(128)       NOT NULL default '', \
                    verify       int(4)             NOT NULL default '0', \
                    registertm   timestamp          NOT NULL default CURRENT_TIMESTAMP, \
                    money        int(4)             NOT NULL default 0, \
                    INDEX        mobile_index(mobile) \
                    )";
    // conn = pro_ptr->getConn();
    return conn->update(sql);
}

bool BusinessProcesser::createBiketable(){
    const char *sql = "\
                    CREATE TABLE IF NOT EXISTS bikeinfo(\
                    id            int               NOT NULL primary key auto_increment, \
                    devno         int               NOT NULL, \
                    status        tinyint(1)        NOT NULL default 0, \
                    trouble       int               NOT NULL default 0, \
                    tmsg          varchar(256)      NOT NULL default '', \
                    latitude      double(10, 6)     NOT NULL default 0, \
                    longitude     double(10, 6)     NOT NULL default 0, \
                    unique(devno) \
                    )";
    // conn = pro_ptr->getConn();
    return conn->update(sql);
}